<%@ page language="java" contentType="text/html; charset=UTF-8"	 pageEncoding="UTF-8"%>
<%@ include file="../include/laypublic.jsp"%>
<!DOCTYPE html>
<html>
<head>
  <title>公司年度预算新增</title>
</head>
<style>
	.fieldset{
		margin-top: 5px;
		margin-bottom: 0px
	}
	.layui-legend{
		background-color:#5fb878;
		font-size:15px !important;
		width:140px;
	}
	.layui-form-item {
	    margin-bottom: 5px;
	    clear: both;
	    *zoom: 1;
	}
	.layui-form-label{width: 180px;}
</style>
<body>
<div class="layui-fluid">
    <div class="layui-card">
	    <div class="layui-tab-item layui-show">
	    	<div style="padding-top:15px;">&nbsp;</div>
			<form class="layui-form" id="addInfo_form" lay-filter="add_info_from">
				<fieldset class="layui-elem-field layui-field-title fieldset"  id="baseInfo">
				  <legend class="layui-btn layui-legend" style="text-align:left;cursor:default;">预算基础信息  ></legend>
				  <div style="margin-top:20px">
				  	<div class="layui-form-item">
				  		<div class="layui-inline">
					      	<label class="layui-form-label">申请公司</label>
					      	<div class="layui-input-inline">
					      		<input type="hidden" name="hrOrgId" value="${bindOrgId}">
								<input type="text" value="${bindOrgName}" style="border:0px;" readonly="readonly" class="layui-input">
					      	</div>
					    </div>
					    <div class="layui-inline">
					    	<label class="layui-form-label">申请部门</label>
				      		<div class="layui-input-inline">
				      			<input type="hidden" name="hrDeptId" value="${bindDeptId}">
								<input type="text" value="${bindDeptName}" style="border:0px;" readonly="readonly" class="layui-input">
				      		</div>
					    </div>
					    <div class="layui-inline">
					    	<label class="layui-form-label">登记人</label>
				      		<div class="layui-input-inline">
				        		<input type="hidden" name="hrStaffApplyId" readonly="readonly" value="${SESSION_KEY_USER_DETAIL.hrStaffId }">
				        		<input type="text" name="staffName" value="${staffName }" readonly="readonly" style="border:0px" class="layui-input">
				      		</div>
					    </div>
				    </div>
				  	<div class="layui-form-item">
				  		<div class="layui-inline">
					      	<label class="layui-form-label">公司名称</label>
					      	<div class="layui-input-inline">
					        	<select name="hrOrgBillId" id="hrOrgBillId" lay-verify="required" lay-filter="add_chooseOrg" lay-search>
				              		<c:if test="${not empty orgInfos}">
				              			<c:forEach items="${orgInfos}" var="org">
				              				<option value="${org.id }" types="${org.types }" <c:if test="${org.id == bindOrgId }">selected</c:if>>${org.compName }</option>
					            		</c:forEach>
				              		</c:if>
				              	</select>
					      	</div>
					    </div>
					    <div class="layui-inline">
					    	<label class="layui-form-label">公司类型</label>
				      		<div class="layui-input-inline">
						        <input type="hidden" name="orgTypes" id="orgTypes" value="${orgTypes }">
						        <input type="hidden" name="billOrgName" id="billOrgName" value="${billOrgName }">
				        		<input name="typeName" id="typeName" value="${orgTypes == '1' ? '总部公司':orgTypes == '2' ? '区域公司':orgTypes == '3' ? '项目公司':'未绑定公司'}" style="border:0px;" readonly="readonly" class="layui-input">
				      		</div>
					    </div>
					    <div class="layui-inline">
					    	<label class="layui-form-label">预算年度</label>
				      		<div class="layui-input-inline">
						        <input type="text" class="layui-input" id="sent-laydate-year" name="belongsYear" lay-verify="required" readonly>
				      		</div>
					    </div>
				    </div>
		  		</div>
			</fieldset>
				<fieldset class="layui-elem-field layui-field-title fieldset" id="houseInfo">
			  		<legend class="layui-btn layui-legend" style="text-align:left;cursor:default;">年度预算明细  ></legend>
				  	<div style="margin-top:20px">
				  		<div class="layui-form-item" style="margin: 0 20px;">
				  			<table class="layui-table layuiadmin-page-table" lay-skin="line">
			                  <thead>
			                    <tr>
			                      <th>月份</th>
			                      <th>管理费用（元）</th>
			                      <th>营销费用（元）</th>
			                      <th>自行承接建安额（元）</th>
			                    </tr> 
			                  </thead>
			                  <tbody>
			                    <tr>
			                      <td>1<input type="hidden" name="months" value="1"></td>
			                      <td>
				                  	<div class="layui-input-inline">
				                    	<input type="text" name="manageFee" maxlength="13" lay-verify="required|floatAmount" onblur="calcSumAmount(this);arabiaToCN(this,1);" autocomplete="off" class="layui-input">
				                    </div>
			                      </td>
			                      <td>
			                      	<div class="layui-input-inline">
			                      		<input type="text" name="saleFee" maxlength="13" lay-verify="required|floatAmount" onblur="calcSumAmount(this);arabiaToCN(this,1);" autocomplete="off" class="layui-input">
			                      	</div>
			                      </td>
			                      <td>
			                      	<div class="layui-input-inline">
			                      		<input type="text" name="selfCae" maxlength="13" lay-verify="required|floatAmount" onblur="calcSumAmount(this);arabiaToCN(this,1);" autocomplete="off" class="layui-input">
			                      	</div>
			                      </td>
			                    </tr>
			                    <tr>
			                      <td>2<input type="hidden" name="months" value="2"></td>
			                      <td>
				                  	<div class="layui-input-inline">
				                    	<input type="text" name="manageFee" maxlength="13" lay-verify="required|floatAmount" onblur="calcSumAmount(this);arabiaToCN(this,1);" autocomplete="off" class="layui-input">
				                    </div>
			                      </td>
			                      <td>
			                      	<div class="layui-input-inline">
			                      		<input type="text" name="saleFee" maxlength="13" lay-verify="required|floatAmount" onblur="calcSumAmount(this);arabiaToCN(this,1);" autocomplete="off" class="layui-input">
			                      	</div>
			                      </td>
			                      <td>
			                      	<div class="layui-input-inline">
			                      		<input type="text" name="selfCae" maxlength="13" lay-verify="required|floatAmount" onblur="calcSumAmount(this);arabiaToCN(this,1);" autocomplete="off" class="layui-input">
			                      	</div>
			                      </td>
			                    </tr>
			                    <tr>
			                      <td>3<input type="hidden" name="months" value="3"></td>
			                      <td>
				                  	<div class="layui-input-inline">
				                    	<input type="text" name="manageFee" maxlength="13" lay-verify="required|floatAmount" onblur="calcSumAmount(this);arabiaToCN(this,1);" autocomplete="off" class="layui-input">
				                    </div>
			                      </td>
			                      <td>
			                      	<div class="layui-input-inline">
			                      		<input type="text" name="saleFee" maxlength="13" lay-verify="required|floatAmount" onblur="calcSumAmount(this);arabiaToCN(this,1);" autocomplete="off" class="layui-input">
			                      	</div>
			                      </td>
			                      <td>
			                      	<div class="layui-input-inline">
			                      		<input type="text" name="selfCae" maxlength="13" lay-verify="required|floatAmount" onblur="calcSumAmount(this);arabiaToCN(this,1);" autocomplete="off" class="layui-input">
			                      	</div>
			                      </td>
			                    </tr>
			                    <tr>
			                      <td>4<input type="hidden" name="months" value="4"></td>
			                      <td>
				                  	<div class="layui-input-inline">
				                    	<input type="text" name="manageFee" maxlength="13" lay-verify="required|floatAmount" onblur="calcSumAmount(this);arabiaToCN(this,1);" autocomplete="off" class="layui-input">
				                    </div>
			                      </td>
			                      <td>
			                      	<div class="layui-input-inline">
			                      		<input type="text" name="saleFee" maxlength="13" lay-verify="required|floatAmount" onblur="calcSumAmount(this);arabiaToCN(this,1);" autocomplete="off" class="layui-input">
			                      	</div>
			                      </td>
			                      <td>
			                      	<div class="layui-input-inline">
			                      		<input type="text" name="selfCae" maxlength="13" lay-verify="required|floatAmount" onblur="calcSumAmount(this);arabiaToCN(this,1);" autocomplete="off" class="layui-input">
			                      	</div>
			                      </td>
			                    </tr>
			                    <tr>
			                      <td>5<input type="hidden" name="months" value="5"></td>
			                      <td>
				                  	<div class="layui-input-inline">
				                    	<input type="text" name="manageFee" maxlength="13" lay-verify="required|floatAmount" onblur="calcSumAmount(this);arabiaToCN(this,1);" autocomplete="off" class="layui-input">
				                    </div>
			                      </td>
			                      <td>
			                      	<div class="layui-input-inline">
			                      		<input type="text" name="saleFee" maxlength="13" lay-verify="required|floatAmount" onblur="calcSumAmount(this);arabiaToCN(this,1);" autocomplete="off" class="layui-input">
			                      	</div>
			                      </td>
			                      <td>
			                      	<div class="layui-input-inline">
			                      		<input type="text" name="selfCae" maxlength="13" lay-verify="required|floatAmount" onblur="calcSumAmount(this);arabiaToCN(this,1);" autocomplete="off" class="layui-input">
			                      	</div>
			                      </td>
			                    </tr>
			                    <tr>
			                      <td>6<input type="hidden" name="months" value="6"></td>
			                      <td>
				                  	<div class="layui-input-inline">
				                    	<input type="text" name="manageFee" maxlength="13" lay-verify="required|floatAmount" onblur="calcSumAmount(this);arabiaToCN(this,1);" autocomplete="off" class="layui-input">
				                    </div>
			                      </td>
			                      <td>
			                      	<div class="layui-input-inline">
			                      		<input type="text" name="saleFee" maxlength="13" lay-verify="required|floatAmount" onblur="calcSumAmount(this);arabiaToCN(this,1);" autocomplete="off" class="layui-input">
			                      	</div>
			                      </td>
			                      <td>
			                      	<div class="layui-input-inline">
			                      		<input type="text" name="selfCae" maxlength="13" lay-verify="required|floatAmount" onblur="calcSumAmount(this);arabiaToCN(this,1);" autocomplete="off" class="layui-input">
			                      	</div>
			                      </td>
			                    </tr>
			                    <tr>
			                      <td>7<input type="hidden" name="months" value="7"></td>
			                      <td>
				                  	<div class="layui-input-inline">
				                    	<input type="text" name="manageFee" maxlength="13" lay-verify="required|floatAmount" onblur="calcSumAmount(this);arabiaToCN(this,1);" autocomplete="off" class="layui-input">
				                    </div>
			                      </td>
			                      <td>
			                      	<div class="layui-input-inline">
			                      		<input type="text" name="saleFee" maxlength="13" lay-verify="required|floatAmount" onblur="calcSumAmount(this);arabiaToCN(this,1);" autocomplete="off" class="layui-input">
			                      	</div>
			                      </td>
			                      <td>
			                      	<div class="layui-input-inline">
			                      		<input type="text" name="selfCae" maxlength="13" lay-verify="required|floatAmount" onblur="calcSumAmount(this);arabiaToCN(this,1);" autocomplete="off" class="layui-input">
			                      	</div>
			                      </td>
			                    </tr>
			                    <tr>
			                      <td>8<input type="hidden" name="months" value="8"></td>
			                      <td>
				                  	<div class="layui-input-inline">
				                    	<input type="text" name="manageFee" maxlength="13" lay-verify="required|floatAmount" onblur="calcSumAmount(this);arabiaToCN(this,1);" autocomplete="off" class="layui-input">
				                    </div>
			                      </td>
			                      <td>
			                      	<div class="layui-input-inline">
			                      		<input type="text" name="saleFee" maxlength="13" lay-verify="required|floatAmount" onblur="calcSumAmount(this);arabiaToCN(this,1);" autocomplete="off" class="layui-input">
			                      	</div>
			                      </td>
			                      <td>
			                      	<div class="layui-input-inline">
			                      		<input type="text" name="selfCae" maxlength="13" lay-verify="required|floatAmount" onblur="calcSumAmount(this);arabiaToCN(this,1);" autocomplete="off" class="layui-input">
			                      	</div>
			                      </td>
			                    </tr>
			                    <tr>
			                      <td>9<input type="hidden" name="months" value="9"></td>
			                      <td>
				                  	<div class="layui-input-inline">
				                    	<input type="text" name="manageFee" maxlength="13" lay-verify="required|floatAmount" onblur="calcSumAmount(this);arabiaToCN(this,1);" autocomplete="off" class="layui-input">
				                    </div>
			                      </td>
			                      <td>
			                      	<div class="layui-input-inline">
			                      		<input type="text" name="saleFee" maxlength="13" lay-verify="required|floatAmount" onblur="calcSumAmount(this);arabiaToCN(this,1);" autocomplete="off" class="layui-input">
			                      	</div>
			                      </td>
			                      <td>
			                      	<div class="layui-input-inline">
			                      		<input type="text" name="selfCae" maxlength="13" lay-verify="required|floatAmount" onblur="calcSumAmount(this);arabiaToCN(this,1);" autocomplete="off" class="layui-input">
			                      	</div>
			                      </td>
			                    </tr>
			                    <tr>
			                      <td>10<input type="hidden" name="months" value="10"></td>
			                      <td>
				                  	<div class="layui-input-inline">
				                    	<input type="text" name="manageFee" maxlength="13" lay-verify="required|floatAmount" onblur="calcSumAmount(this);arabiaToCN(this,1);" autocomplete="off" class="layui-input">
				                    </div>
			                      </td>
			                      <td>
			                      	<div class="layui-input-inline">
			                      		<input type="text" name="saleFee" maxlength="13" lay-verify="required|floatAmount" onblur="calcSumAmount(this);arabiaToCN(this,1);" autocomplete="off" class="layui-input">
			                      	</div>
			                      </td>
			                      <td>
			                      	<div class="layui-input-inline">
			                      		<input type="text" name="selfCae" maxlength="13" lay-verify="required|floatAmount" onblur="calcSumAmount(this);arabiaToCN(this,1);" autocomplete="off" class="layui-input">
			                      	</div>
			                      </td>
			                    </tr>
			                    <tr>
			                      <td>11<input type="hidden" name="months" value="11"></td>
			                      <td>
				                  	<div class="layui-input-inline">
				                    	<input type="text" name="manageFee" maxlength="13" lay-verify="required|floatAmount" onblur="calcSumAmount(this);arabiaToCN(this,1);" autocomplete="off" class="layui-input">
				                    </div>
			                      </td>
			                      <td>
			                      	<div class="layui-input-inline">
			                      		<input type="text" name="saleFee" maxlength="13" lay-verify="required|floatAmount" onblur="calcSumAmount(this);arabiaToCN(this,1);" autocomplete="off" class="layui-input">
			                      	</div>
			                      </td>
			                      <td>
			                      	<div class="layui-input-inline">
			                      		<input type="text" name="selfCae" maxlength="13" lay-verify="required|floatAmount" onblur="calcSumAmount(this);arabiaToCN(this,1);" autocomplete="off" class="layui-input">
			                      	</div>
			                      </td>
			                    </tr>
			                    <tr>
			                      <td>12<input type="hidden" name="months" value="12"></td>
			                      <td>
				                  	<div class="layui-input-inline">
				                    	<input type="text" name="manageFee" maxlength="13" lay-verify="required|floatAmount" onblur="calcSumAmount(this);arabiaToCN(this,1);" autocomplete="off" class="layui-input">
				                    </div>
			                      </td>
			                      <td>
			                      	<div class="layui-input-inline">
			                      		<input type="text" name="saleFee" maxlength="13" lay-verify="required|floatAmount" onblur="calcSumAmount(this);arabiaToCN(this,1);" autocomplete="off" class="layui-input">
			                      	</div>
			                      </td>
			                      <td>
			                      	<div class="layui-input-inline">
			                      		<input type="text" name="selfCae" maxlength="13" lay-verify="required|floatAmount" onblur="calcSumAmount(this);arabiaToCN(this,1);" autocomplete="off" class="layui-input">
			                      	</div>
			                      </td>
			                    </tr>
			                  </tbody>
			                  <tfoot>
			                    <tr>
			                      <td>合计</td>
			                      <td>
				                  	<div class="layui-input-inline">
				                    	<input type="text" name="manageFeeSum" id="manageFeeSum" style="border:0px;" readonly="readonly" class="layui-input">
				                    </div>
			                      </td>
			                      <td>
			                      	<div class="layui-input-inline">
			                      		<input type="text" name="saleFeeSum" id="saleFeeSum" style="border:0px;" readonly="readonly" class="layui-input">
			                      	</div>
			                      </td>
			                      <td>
			                      	<div class="layui-input-inline">
			                      		<input type="text" name="selfCaeSum" id="selfCaeSum" style="border:0px;" readonly="readonly" class="layui-input">
			                      	</div>
			                      </td>
			                    </tr>
			                  </tfoot>
			                </table>
			            </div>
				  	</div>
				</fieldset>
				<div class="layui-form-item" style="position: fixed ! important; right: 30px; bottom:45%;z-index:10000;">
					<div class="layui-input-block">
			      		<button class="layui-btn layui-bg-blue layui-btn-normal layui-btn-lg  layui-btn-radius" type="button" lay-submit lay-filter="addInfo_form_submit" id="addInfo_form_submit">
			      		<i class="layui-icon layui-icon-ok layuiadmin-button-btn"></i>
			      		提交
			      		</button>
			      	</div>
			    </div>
			</form>
  		</div>
	</div>
</div>
  <script>
	//静态资源路径前缀
	var staticPath = '${fileHttpPre}';
	var stateJSON = <infopub:dicJson groupNo="A00010028" />;
	
  layui.config({
    base: '${ctx}/resources/layuiadmin/' //静态资源所在路径
  }).extend({
    index: 'lib/index' //主入口模块
  }).use(['index', 'set', 'upload', 'element', 'laydate'], function(){
    var $ = layui.$
    ,form = layui.form
    ,element = layui.element
    ,laydate = layui.laydate
    ,upload = layui.upload;
    
    laydate.render({
	      elem: '#sent-laydate-year'
	      ,type: 'year'
 		});
 	// 正则校验
	form.verify({
		//验证汉字
	    CHS:[
	    	/^[\u0391-\uFFE5]+$/
	    	,'只能输入汉字'
	  	],
	  	//大于0的正整数
	  	intNumber:[
			/^[1-9]\d*$/
			,'请输入正确的数字'
	  	],
	  	//数字只能有两位小数
	  	floatNumber:[
			/^([-]?)([0-9](\d+)?(\.\d{1,2})?$)|(^\d\.\d{1,2}$)/
			,'请输入正确的数字'
	  	],
	  	//数字大于等于0，并只能有两位小数
	  	floatAmount:[
			/^([0-9](\d+)?(\.\d{1,2})?$)|(^\d\.\d{1,2}$)/
			//var pattern=/^((\d+\.\d*[1-9]\d{1})|(\d*[1-9]\d*\.\d{2}))$/; 
			,'请输入正确的数字'
	  	]
	});
    
   	//监听提交
  	form.on('submit(addInfo_form_submit)', function(data){
  		$("#addInfo_form_submit").removeAttr("lay-submit").removeClass("layui-bg-blue").addClass("layui-btn-disabled");
  		layer.load();
       	//提交 Ajax 成功后，静态更新表格中的数据
       	$.ajax({
           	type : 'post',
			url : basePath + '/orgBudget/save',
           	data: $('#addInfo_form').serialize(),
			success:function(result){
				if(result.success){
					layer.closeAll('loading'); //关闭loading
					layer.msg('提交成功~',{icon: 1});
					//两秒后关闭当前页面
					setTimeout(function(){
						/**
						 * 查找父菜单，并刷新
						 */
						var topDoc = $(window.top.document);
						var path = basePath + '/orgBudget/list';
						// 获取页面名称
						var name = topDoc.find(".layui-nav-item [lay-href^='" + path + "']").text();
						if(name == '' || name == null){
							name = '公司年度预算';
						}
						window.parent.layui.index.openTabsPage(path, name);
						var iframe = window.parent.layui.admin.tabsBody(window.parent.layui.admin.tabsPage.index).find(".layadmin-iframe");
						iframe[0].contentWindow.location.reload(true);
						
						/**
						 * 关闭当前页
						 */
						var currPath = basePath + '/orgBudget/add';
						var layid = topDoc.find("li[lay-id^='" + currPath + "']").attr('lay-id');
						window.parent.layui.element.tabDelete('layadmin-layout-tabs', layid);//关闭当前页
				        }, 2000);
				}else{
					layer.closeAll('loading'); //关闭loading
  					$("#addInfo_form_submit").removeClass("layui-btn-disabled").addClass("layui-bg-blue").attr("lay-submit","");
					layer.msg(result.msg,{icon: 7});
			  	}
			}
       	});
   	});  
 	// data-type事件
    $('.layui-btn.layuiadmin-btn-admin').on('click', function(){
      var type = $(this).data('type');
      active[type] ? active[type].call(this) : '';
    });
 	
  	//新增-公司名称select监听
    form.on('select(add_chooseOrg)', function(data){
    	var types = $("#hrOrgBillId").find("option:selected").attr("types");
    	var orgName = data.elem[data.elem.selectedIndex].text;
    	var orgId = data.value;
    	$("#billOrgName").val(orgName);
		$("#orgTypes").val(types);
		if(types == '1'){
			$("#typeName").val("总部公司");
		}else if(types == '2'){
			$("#typeName").val("区域公司");
		}else if(types == '3'){
			$("#typeName").val("项目公司");
		}
	});
  	
  });

	//计算费用总额
	function calcSumAmount(obj){
		var $ = layui.$;
		if (obj.value == '' || obj.value == null) {
			return;
		}
		var rgx = /^([-]?)([0-9](\d+)?(\.\d{1,2})?$)|(^\d\.\d{1,2}$)/;
		var boolrgx = rgx.test(obj.value);// true 
		if (!boolrgx){
			obj.value=0;
			layer.msg('请输入正确数字，且保留两位小数！');
		}
		var name = obj.name;
		var totalAmount = 0;
  		$("input[name=" + name + "]").each(function(){
			var tId = $(this).val();
			if(tId != '' && parseFloat(tId) > 0){
				totalAmount = totalAmount + parseFloat(tId);
			}
		});
  		$("#"+name+"Sum").val(totalAmount.toFixed(2));
	}
  </script>
</body>
</html>

